﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint
{
    public class LinkedTextRange : LinkedObject
    {
        public LinkedTextRange() { } // Parameterless constructor needed for serialization.

        public LinkedTextRange(Ppt.TextRange textRange)
        {
            TextRange = new ResolvableTextRange(textRange); // Provide caching of the shape object by passing in a CachedShape object.
            //Target = new ResolvableTextRange(textRange); // Provide caching of the shape object by passing in a CachedShape object.
        }

        public ResolvableTextRange TextRange { get; set; }

        //public override ResolvableShape TargetShape
        //{
        //    get { return TextRange.Shape; }
        //}

        public override void UpdateValue()
        {
            Ppt.TextRange textRange = TextRange.Resolve() as Ppt.TextRange;
            textRange.Text = Source.GetValue();
        }

        //public override bool IsSelected
        //{
        //    get
        //    {
        //            Ppt.Application app = Globals.Application;
        //            Ppt.Selection selection = app.ActiveWindow.Selection;

        //            return TextRange.Contains(selection.TextRange);
        //    }
        //}

        //public override void Select()
        //{
        //    Ppt.TextRange textRange = TextRange.Resolve() as Ppt.TextRange;
        //    textRange.Select();
        //}

        public override string ToString()
        {
            Ppt.Shape shape = TextRange.Shape.Resolve() as Ppt.Shape;

            return string.Format("{0}: TextRange", shape.Name);
        }
    }
}
